package sjtu.ist.warehouse4ws.jcr;
import java.util.ArrayList;

import javax.jcr.RepositoryException;

import sjtu.ist.warehouse4ws.model.ModelFilePojo;
import sjtu.ist.warehouse4ws.tool.FileIO;

import com.opensymphony.xwork2.ActionSupport;

public class TestjcrAction  extends ActionSupport{
	Testjcr testjcrService;
	RepositoryMoudl repositoryMoudlService;

	public void setRepositoryMoudlService(RepositoryMoudl repositoryMoudlService) {
		this.repositoryMoudlService = repositoryMoudlService;
	}


	public void setTestjcrService(Testjcr testjcrService) {
		this.testjcrService = testjcrService;
	}

	
	public String testjcr() throws RepositoryException {

		//testjcrService.testjcr();
		testjcrService.testjcrVersion();
		
		return SUCCESS;
	}
	public String testCreatData(){
		String companyId="0";

		String modelType="demo2";
		String path=companyId+"/"+modelType;
		repositoryMoudlService.createWorkSpace(companyId);
		repositoryMoudlService.addModelNode(companyId, modelType);
		String docpath="D:/demo2";
		FileIO fio=new FileIO();
		ModelFilePojo mfp=fio.getAllModelData(docpath);
		repositoryMoudlService.importAllModel(companyId, modelType, mfp);
		//String modelType="demo2";
		String versionId="1.0";
		String type="domain";
//		String path=companyId+"/"+modelType;
//		repositoryMoudlService.createWorkSpace(companyId);
//		repositoryMoudlService.addModelNode(companyId, modelType);
//		String docpath="E:/Users/chenqidou/Desktop/demo2";
//		FileIO fio=new FileIO();
//		ModelFilePojo mfp=fio.getAllModelData(docpath);
//		repositoryMoudlService.importAllModel(companyId, modelType, mfp);
	    repositoryMoudlService.getAllFile(companyId, modelType, versionId,type);

		System.out.print("------------导入模型成功");
//		repositoryMoudlService.getModelXmlFile(path);
		
		return SUCCESS;
	}
	public String removeData(){
		String companyId="0";

		String modelType="demo2";

		//String modelType="LogisticsProcess";

		String path=companyId+"/"+modelType;
		repositoryMoudlService.removeNode(path);
		modelType="demo2";
		path=companyId+"/"+modelType;
		repositoryMoudlService.removeNode(path);
		return SUCCESS;
	}
}
